package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.NbGpDashboard;
import com.stylefeng.guns.modular.system.service.INbGpDashboardService;

/**
 * dashboard控制器
 *
 * @author fengshuonan
 * @Date 2018-07-19 22:43:20
 */
@Controller
@RequestMapping("/nbGpDashboard")
public class NbGpDashboardController extends BaseController {

    private String PREFIX = "/system/nbGpDashboard/";

    @Autowired
    private INbGpDashboardService nbGpDashboardService;

    /**
     * 跳转到dashboard首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "nbGpDashboard.html";
    }

    /**
     * 跳转到添加dashboard
     */
    @RequestMapping("/nbGpDashboard_add")
    public String nbGpDashboardAdd() {
        return PREFIX + "nbGpDashboard_add.html";
    }

    /**
     * 跳转到修改dashboard
     */
    @RequestMapping("/nbGpDashboard_update/{nbGpDashboardId}")
    public String nbGpDashboardUpdate(@PathVariable Integer nbGpDashboardId, Model model) {
        NbGpDashboard nbGpDashboard = nbGpDashboardService.selectById(nbGpDashboardId);
        model.addAttribute("item",nbGpDashboard);
        LogObjectHolder.me().set(nbGpDashboard);
        return PREFIX + "nbGpDashboard_edit.html";
    }

    /**
     * 获取dashboard列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return nbGpDashboardService.selectList(null);
    }

    /**
     * 新增dashboard
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(NbGpDashboard nbGpDashboard) {
        nbGpDashboardService.insert(nbGpDashboard);
        return SUCCESS_TIP;
    }

    /**
     * 删除dashboard
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer nbGpDashboardId) {
        nbGpDashboardService.deleteById(nbGpDashboardId);
        return SUCCESS_TIP;
    }

    /**
     * 修改dashboard
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(NbGpDashboard nbGpDashboard) {
        nbGpDashboardService.updateById(nbGpDashboard);
        return SUCCESS_TIP;
    }

    /**
     * dashboard详情
     */
    @RequestMapping(value = "/detail/{nbGpDashboardId}")
    @ResponseBody
    public Object detail(@PathVariable("nbGpDashboardId") Integer nbGpDashboardId) {
        return nbGpDashboardService.selectById(nbGpDashboardId);
    }
}
